<%--
  Created by IntelliJ IDEA.
  User: apple
  Date: 2022/4/26
  Time: 3:41 下午
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%String path = request.getContextPath()+"/";%>
<!doctype html>
<html>
<head>
    <base href="<%=path%>">
    <title>用户新增/编辑</title>
    <link href="css/bootstrap.min.css?v=3.3.7" rel="stylesheet">
    <link href="css/plugins/switchery/switchery.css" rel="stylesheet">
</head>
<style>
    .error{
        color: red;
        position: absolute;
        line-height:40px;
        right:0px;
    }
</style>
<body style="overflow-x: hidden">
<form class="form-horizontal" id="objectForm">
    <input type="hidden" name="deptId" value="${dept.deptId}"/>
    <div class="form-group">
        <div class="col-sm-12">
            <label  class="col-sm-4 control-label">上级部门：</label>
            <div class="col-sm-8">
                <input type="hidden" name="parentId" id="parentId" value="${dept.parentId}">
                <input type="text" id="parentName" class="form-control" placeholder="Search for..." value="${parentName}" onclick="showTree();" style="width: 60%;float:left">
                <span class="input-group-btn">
                    <button class="btn btn-default" type="button" onclick="showTree();"><i class="glyphicon glyphicon-search"></i></button>
                </span>
            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-12">
            <label for="deptName" class="col-sm-4 control-label">*部门名称</label>
            <div class="col-sm-8">
                <input type="text"  class="form-control" name="deptName" value="${dept.deptName}" id="deptName" placeholder="部门名称">

            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-12">
            <label for="orderNum" class="col-sm-4 control-label">*显示顺序</label>
            <div class="col-sm-8">
                <input type="text"  class="form-control" name="orderNum" value="${dept.orderNum}" id="orderNum" placeholder="显示顺序">
            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-12">
            <label for="chargeName" class="col-sm-4 control-label">负责人</label>
            <div class="col-sm-8">
                <input type="text"  class="form-control" id="chargeName" name="chargeName" value="${dept.chargeName}" placeholder="负责人">
            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-12">
            <label for="phoneNum" class="col-sm-4 control-label">联系电话</label>
            <div class="col-sm-8">
                <input type="text"  class="form-control" id="phoneNum" name="phoneNum" value="${dept.phoneNum}" placeholder="联系电话">
            </div>
        </div>
    </div>
    <div class="form-group" >
        <div class="col-sm-4"></div>
        <div class="col-sm-8" style="align:center">
            <button type="button" class="btn btn-warning" onclick="save();"><i class="glyphicon glyphicon-saved"></i>保存</button>
            <button type="reset" class="btn btn-warning"><i class="glyphicon glyphicon-refresh"></i>重置</button>
        </div>
    </div>
</form>
</body>
<script src="js/jquery.min.js?v=2.1.4"></script>
<script src="js/bootstrap.min.js?v=3.3.7"></script>
<script src="js/plugins/layer/layer.min.js"></script>
<script src="js/plugins/validate/jquery.validate.min.js"></script>
<script src="js/plugins/validate/messages_zh.min.js"></script>
<!-- Switchery -->
<script src="js/plugins/switchery/switchery.js"></script>
<script src="js/sofwin.js"></script>
<script>
    var elem = document.querySelector('.js-switch');
    var switchery = new Switchery(elem);
    // 给当前form表单添加了表单验证规则
    $("form").validate({
        rules:{
            deptName:{
                required:true
            },
            orderNum:{
                required:true
            },
            email:{
                email:true
            }
        },
        messages:{
            "deptName":{
                required: '部门名称不能为空'
            },
            "orderNum":{
                required:'显示顺序不能为空'
            },
            "email":{
                email:'邮箱格式不正确'
            }
        }
    });
    function save(){
        if(!$("form").valid()){
            // true验证规则全部成功
            return;
        }
        $.operator.post('dept/save',$("form").serialize());
    }

    function showTree(){
        $.modal.addWinBtns('选择上级部门','dept/tree',['400px','400px'],function(index, layero){
            var body = layer.getChildFrame('body', index);
            var iframeWin = window[layero.find('iframe')[0]['name']];
            iframeWin.setParentValue();
            // document..contentWindow.setParentValue();
        });
    }
    function close(){
        layer.close(index);
    }

    function setParent(deptName,deptId){
        $("#parentId").val(deptId);
        $("#parentName").val(deptName);
    }

</script>
</html>
